﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ltModel.Model;
using ltModel.BLL;
using ltModel;

public partial class ProjectDetail : System.Web.UI.Page
{
    ltModel.BLL.ProjectBLL projectBLL = new ltModel.BLL.ProjectBLL();
    ProjectStreetBLL projectStreetBLL = new ProjectStreetBLL();
    ProjectTypeBLL projectTypeBLL = new ProjectTypeBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<ProjectStreet> listStreet = projectStreetBLL.GetList();
            List<ProjectType> listType = projectTypeBLL.GetList();

            string id = Request.QueryString["ProjectID"] as string;
            if (Str.IsInt(id))
            {
                ltModel.Model.Project project = projectBLL.GetModel(int.Parse(id));
                if (project != null)
                {
                    lblProjectName.Text = project.ProjectName;
                    lblOrganizor.Text = project.Organizer;
                    lblServiceLocation.Text = project.ServiceLocation;
                    lblProjectContent.Text = project.ProjectContent;
                    lblRecruitmentLocation.Text = project.RecruitmentLocation;
                    lblRecruitmentAmount.Text = project.RecruitmentAmount.ToString();
                    lblRegistrationDeadLine.Text = project.RegistrationDeadLine.ToString("yyyy-MM-dd");
                    lblRegistrationRequirement.Text = project.RegistrationRequirement;
                    lblContact.Text = project.Contact;
                    lblStreet.Text = this.GetStreetName(listStreet, project.ProjectStreetID);
                    lblType.Text = this.GetTypeName(listType, project.ProjectTypeID);
                    if (!string.IsNullOrEmpty(project.Attachment.Trim()))
                        hlFile.NavigateUrl = project.Attachment;
                    else
                        hlFile.Text = "无";
                }
                else
                {
                    AlertNoProject();
                }
            }
            else
            {
                AlertNoProject();
            }
        }
    }

    private void AlertNoProject()
    {
        ltModel.MessageBox.Show(this, "项目不存在，请返回上一级！");
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="listStreet"></param>
    /// <param name="streetID"></param>
    /// <returns></returns>
    private string GetStreetName(List<ProjectStreet> listStreet, int streetID)
    {
        foreach (ProjectStreet item in listStreet)
        {
            if (item.StreetID == streetID)
                return item.StreetName;
        }

        return string.Empty;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="listStreet"></param>
    /// <param name="streetID"></param>
    /// <returns></returns>
    private string GetTypeName(List<ProjectType> listType, int typeID)
    {
        foreach (ProjectType item in listType)
        {
            if (item.TypeID == typeID)
                return item.TypeName;
        }

        return string.Empty;
    }
}